#include <fhepython/PyVar.h>
#include <fhepython/PyEnv.h>

namespace fhe
{
  namespace python
  {
    PyVar::PyVar( const std::string& name, Node* node, boost::python::object get, boost::python::object set )
      : name_( name )
      , node_( node )
      , get_( get )
      , set_( set )
    {
    }
    
    std::string PyVar::name() const
    {
      return name_;
    }
    
    Val PyVar::get() const
    {
      return PyEnv::instance().convertVal( get_( node_ ) );
    }
    
    void PyVar::set( Val val )
    {
      FHE_ASSERT_MSG( set_ != boost::python::object(), "unable to set py var %s with no set_ method", name_.c_str() );
      set_( node_, PyEnv::instance().convertVal( val ) );
    }
  }
}
